package com.xkl.springdoc.controller.api;

import com.xkl.springdoc.common.R;
import com.xkl.springdoc.request.RoleDTO;
import com.xkl.springdoc.service.IRoleService;
import com.xkl.springdoc.validate.AddGroup;
import com.xkl.springdoc.validate.EditGroup;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 角色管理
 *
 * @version: 1.0.0-SNAPSHOT
 * @author: 码农小卡拉
 * @createTime: 2025-09-15 12:39
 **/
@Tag(name = "角色管理", description = "角色新增、查询、修改、删除等核心接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/role")
public class RoleController {

    private final IRoleService iRoleService;

    /**
     * 根据id查询角色
     * @param id
     * @return
     */
    @GetMapping("/selectById")
    public R selectById(@RequestParam("id") Long id) {
        return iRoleService.getRole(id);
    }

    /**
     * 新增角色
     * @param roleDTO
     * @return
     */
    @PostMapping("/addRole")
    public R addRole(@Validated(AddGroup.class) @RequestBody RoleDTO roleDTO) {
        return iRoleService.addRole(roleDTO);
    }

    /**
     * 删除角色
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    public R deleteById(@RequestParam("id") Long id) {
        return iRoleService.deleteRole(id);
    }

    /**
     * 更新角色
     * @param roleDTO
     * @return
     */
    @PutMapping("/editRole")
    public R editRole(@Validated(EditGroup.class) @RequestBody RoleDTO roleDTO) {
        return iRoleService.updateRole(roleDTO);
    }

    /**
     * 查询所有角色
     * @return
     */
    @GetMapping("/selectAll")
    public R selectAll() {
        return iRoleService.getRoles();
    }
}
